<?php
class SpricityIterator implements iterator,ArrayAccess,Countable{
	private $option = array();
	private $allowed = array();
	public function __construct($array = array()){
		foreach($array as $key){
			$this->option[$key]=null;
		}
		$this->allowed = array_flip($array);
	}
	public function __get($key){
		if(isset($this->option[$key]))
			return $this->option[$key];
		return null;
	}
	public function __set($key,$val){
		if (isset($this->setters[$key]))
			$val = $this->setters[$key]($val);
		$this->option[$key] = $val;
	}
	public function __unset($key){
		unset($this->option[$key]);
	}
	public function __isset($key) {
		return isset($this->allowed[$key]);
	}
	public function current(){
		return current($this->option);
	}
	public function key(){
		return key($this->option);
	}
	public function next(){
		return next($this->option);
	}
	public function rewind(){
		foreach($this->option as $k => $v){
			if(is_null($v)){
				unset($this->option[$k]);
			}
		}
		reset($this->option);
	}
	public function valid(){
		return (boolean) current($this->option);
	}

	public function offsetExists($index){
		return $this->__isset($index);
	}

	public function offsetGet($index){
		return $this->__get($index);
	}

	public function offsetSet($index,$value){
		$this->__set($index,$value);
	}

	public function offsetUnset($index){
		$this->__unset($index);
	}

	public function count() {
		$i = 0;
		foreach($this->option as $v){
			if(!is_null($v))
				$i++;
		}
		return $i;
	}

}